package com.laiyizhan.common.mapper;

import com.laiyizhan.common.model.Admin;
import org.apache.ibatis.annotations.*;


public interface AdminMapper {
    @Delete({
            "delete from t_admin",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
            "insert into t_admin (username, password, ",
            "enable, create_date)",
            "values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
            "#{enable,jdbcType=BIGINT}, #{createDate,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(Admin record);

    int insertSelective(Admin record);

    @Select({
            "select",
            "id, username, password, enable, create_date",
            "from t_admin",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Admin selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Admin record);

    @Update({
            "update t_admin",
            "set username = #{username,jdbcType=VARCHAR},",
            "password = #{password,jdbcType=VARCHAR},",
            "enable = #{enable,jdbcType=BIGINT},",
            "create_date = #{createDate,jdbcType=TIMESTAMP}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Admin record);

    /**
     * 根据username查询管员用户
     *
     * @param username
     * @return
     */
    @Select({"select",
            "id, username, password, enable, create_date",
            "from t_admin",
            "where username = #{username,jdbcType=VARCHAR} and `enable` = 1"})
    Admin selectByUsername(String username);
}